package com.xunqi.ad.controller;

import com.alibaba.fastjson.JSON;
import com.xunqi.ad.entity.AdPlan;
import com.xunqi.ad.exception.AdException;
import com.xunqi.ad.form.AdPlanForm;
import com.xunqi.ad.form.AdPlanGetForm;
import com.xunqi.ad.service.IAdPlanService;
import com.xunqi.ad.vo.AdPlanResponseVo;
import com.xunqi.ad.vo.ResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Description:
 * @Created with IntelliJ IDEA.
 * @author: 夏沫止水
 * @createTime: 2020-04-30 21:52
 **/
@RestController
@Slf4j
public class AdPlanOPController {

    @Resource
    private IAdPlanService adPlanService;

    @PostMapping(value = "/create/addPlan")
    public ResponseVo<AdPlanResponseVo> createAdPlan(@Valid @RequestBody AdPlanForm form) throws AdException {

        log.info("ad-sponsor:createAdPlan -> {}", JSON.toJSONString(form));


        ResponseVo<AdPlanResponseVo> adPlanResponseVo = adPlanService.createAdPlan(form);

        return adPlanResponseVo;
    }

    @PostMapping(value = "/get/adPlan")
    public ResponseVo<List<AdPlan>> getAdPlanByIds(@Valid @RequestBody AdPlanGetForm form) throws AdException {

        log.info("ad-sponsor:getAdPlanByIds -> {}", JSON.toJSONString(form));

        ResponseVo<List<AdPlan>> adPlanByIdsResponseVo = adPlanService.getAdPlanByIds(form);

        return adPlanByIdsResponseVo;
    }


    @PutMapping(value = "/update/addPlan")
    public ResponseVo<AdPlanResponseVo> updateAdPlan(@Valid @RequestBody AdPlanForm form) throws AdException {

        log.info("ad-sponsor:updateAdPlan -> {}", JSON.toJSONString(form));

        ResponseVo<AdPlanResponseVo> adPlanResponseVoResponseVo = adPlanService.updateAdPlan(form);

        return adPlanResponseVoResponseVo;

    }


    @DeleteMapping(value = "/delete/addPlan")
    public ResponseVo deleteAdPlan(@Valid @RequestBody AdPlanForm form) throws AdException {

        log.info("ad-sponsor:deleteAdPlan -> {}", JSON.toJSONString(form));

        ResponseVo responseVo = adPlanService.deleteAdPlan(form);

        return responseVo;
    }

}
